package org.wenbo.override.tools.html;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;


public class Html {
	public static Html me(){
		return new Html();
	}
	public String getUrlHtmlCode(String url) {
        BufferedReader in = null;
        String html = null;
        URL u;
        try {
            u = new URL(url);
            in = new BufferedReader(new InputStreamReader(u.openStream()));
            String line = null;
            while ((line = in.readLine()) != null) {
                //line=new String(line.getBytes("UTF-8"),"iso-8859-1");
                html += line;
            }
        } catch (IOException ex) {
            
        }
        return html;
    }

	public String clearHTML(String input) {
		//length  截取 长度   后面加点 dot
		if (input == null || input.trim().equals("")) {
			return "";
		}
		// 去掉所有html元素,
		String str = input.replaceAll("\\&[a-zA-Z]{1,10};", "").replaceAll(
				"<[^>]*>", "");
		str = str.replaceAll("[(/>)<]", "");
		return str;
	}
	public String clearHTML(String input, int length,String dot) {
		//length  截取 长度   后面加点 dot
		input=clearHTML(input);
		int len = input.length();
		if (len <= length) {
			return input;
		} else {
			input = input.substring(0, length);
			input += dot;
		}
		return input;
	}
}
